<template>
  <div style="margin-bottom: 20px;">
    <el-dialog :title="edit_main_title" append-to-body v-dialogDrag :visible.sync="edit_flag"
               @open="handleOpenConfig" :before-close="handleClose">
      <el-row>
        <el-col style="width: 120px;text-align: right;margin-right: 10px;line-height: 32px;height: 32px;">车架号(vin)
        </el-col>
        <el-input placeholder="vin码-回车查询" v-model="scanQueryParams.lotNo1"
                  style="margin-right: 10px;width: 200px" clearable @keyup.enter.native="getReceiveKeyInfo"></el-input>
        <span>
          <el-button type="primary" size="small" :disabled="buttonDisable" @click="receiveOutCertificateClick">领取合格证书</el-button>
          <el-button type="primary" size="small" :disabled="buttonDisable" @click="giveOutCertificateClick">发放合格证书</el-button>
        </span>
      </el-row>
      <hr>
      <el-form ref="outShipForm" :model="receiveKeyParams" label-width="120px" :inline="true">
        <el-form-item label="订单号: ">
          <div class="w200 printBig">{{isBlank(receiveKeyParams.ownerOrderNo)}}</div>
        </el-form-item>
        <el-form-item label="VIN: ">
          <div class="w200 printBig">{{isBlank(receiveKeyParams.lotNo1)}}</div>
        </el-form-item>
        <el-form-item label="车型:">
          <div class="w200 printBig">{{isBlank(receiveKeyParams.materielId)}}</div>
        </el-form-item>
        <el-form-item label="货主: ">
          <div class="w200 printBig">{{isBlank(receiveKeyParams.ownerId)}}</div>
        </el-form-item>
        <el-form-item label="收货仓库: ">
          <div class="w200 printBig">{{isBlank(receiveKeyParams.storeHouseName)}}</div>
        </el-form-item>
        <el-form-item label="入库时间: ">
          <div class="w200 printBig">{{isBlank(receiveKeyParams.gmtCreate)}}</div>
        </el-form-item>
        <el-form-item label="库区: ">
          <div class="w200 printBig">{{isBlank(receiveKeyParams.areaCode)}}</div>
        </el-form-item>
        <el-form-item label="库位: ">
          <div class="w200 printBig">{{isBlank(receiveKeyParams.locationCode)}}</div>
        </el-form-item>
        <el-form-item label="合格证状态: ">
          <div class="w200 printBig">{{isBlank(receiveKeyParams.certificatStatus) | certificatStatus2Filter}}</div>
        </el-form-item>
        <el-form-item label="合格证发放人: ">
          <div class="w200 printBig">{{isBlank(receiveKeyParams.giveoutUser)}}</div>
        </el-form-item>
        <el-form-item label="合格证领取人: ">
          <div class="w200 printBig">{{isBlank(receiveKeyParams.giveoutDate)}}</div>
        </el-form-item>
        <el-form-item label="发放合格证时间: ">
          <div class="w200 printBig">{{isBlank(receiveKeyParams.receiveUser)}}</div>
        </el-form-item>
      </el-form>
      <div style="height:20px"></div>
    </el-dialog>
  </div>
</template>

<script type="text/javascript">
  import * as recordAPI from '@/api/inbound/inboundRecord'
  export default {
    name: '',
    components: {
    },
    props: ['edit_flag', 'edit_main_title', 'edit_select_row', 'edit_params'],
    data() {
      return {
        buttonDisable: true,
        receiveKeyParams: {
          id: '',
          keyStatus: '',
          ownerOrderNo: '',
          lotNo1: '',
          materielId: '',
          ownerId: '',
          storeHouseName: '',
          gmtCreate: '',
          areaCode: '',
          locationCode: '',
          certificatStatus: '',
          giveoutUser: '',
          giveoutDate: '',
          receiveUser: ''
        },
        scanQueryParams: {
          lotNo1: null
        },
        printCodeParam: {
          printDisable: true,
          lotNo1: null,
          locationCode: null,
          areaCode: null,
          ownerOrderNo: null,
          imgBase64: null,
          imgBase64Url: null,
          destAddress: null
        },
        title_data: {},
        table_data: []
      }
    },
    methods: {
      // 弹窗页打开初始
      handleOpenConfig(data) {
        this.buttonDisable = true
        this.receiveKeyParams = {
          id: '',
          keyStatus: '',
          ownerOrderNo: '',
          lotNo1: '',
          materielId: '',
          ownerId: '',
          storeHouseName: '',
          gmtCreate: '',
          areaCode: '',
          locationCode: '',
          certificatStatus: '',
          giveoutUser: '',
          giveoutDate: '',
          receiveUser: ''
        }
      },
      // 输入 车架号 查询
      getReceiveKeyInfo() {
        const queryParam = {}
        queryParam.lotNo1 = this.scanQueryParams.lotNo1
        queryParam.houseId = this.$store.getters.currentStorehouse.id
        recordAPI.getReceiveKeyInfo(queryParam).then(result => {
          if (result.code === 0) {
            this.receiveKeyParams = result.data
            this.buttonDisable = false
          }
        }).catch(() => {
          this.printCodeParam.printDisable = true
          this.buttonDisable = true
        })
      },
      // 领取
      receiveOutCertificateClick() {
        const that = this
        recordAPI.receiveOutCertificat({ putawayLineIds: that.receiveKeyParams.id }).then(result => {
          that.$message({
            message: '领取成功',
            type: 'success',
            duration: 2000
          })
          that.handleClose()
        })
      },
      // 发放
      giveOutCertificateClick() {
        const that = this
        recordAPI.giveOutCertificat({ putawayLineIds: that.receiveKeyParams.id }).then(result => {
          that.$message({
            message: '发放成功',
            type: 'success',
            duration: 2000
          })
          that.handleClose()
        })
      },
      isBlank(val) {
        if (val) {
          return val
        } else {
          return ''
        }
      },
      confirmClick() {
        this.$emit('edit-close', false)
      },
      handleClose() {
        this.$emit('edit-close', false)
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
